<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../../../query.header.jsp"%>
<style type="text/css">
#_body {
	background: #FFFFFF url() repeat-x;
}
</style>

<script type="text/javascript">

var _userId = "${param.userId}";

var _roleList;
$("#_roleList").ready(function() {
	_userList = $("#_roleList").jslist({
		core: { 
			listUrl:ctx + "/biz/system/role/unbind/list.json",
			countUrl:ctx + "/biz/system/role/unbind/count.json",
			queryParams: {"userId":_userId},
			columnMetadatas:[{width:100,title:"名称",name:"name"},
							{width:120,title:"编码",name:"code"},
							{title:"描述",name:"description"}]},
		title: {title:"未绑定角色列表",titleType:"gridHeader"},
		selectable: {selectType:"checkbox"},
		plugins:["title","filter","selectable"]
	}).jslist("refresh");
});
   
function _beforeConfirm(callback) {
	var selectedItems = _userList.jslist("getSelectedItems");
	if (selectedItems.length == 0) {
		$.alert("请选择角色！");
		return false;
	}

	var _roleIds = $(selectedItems).map(function(i,item){
		return item.id;
	}).get().join(",");

	var result = true;
	
	$.ajax({
		type: "POST",
		url: ctx + "/biz/system/user/bindRole.json",
		data: {"userId":_userId,
			"roleIds":_roleIds},
		dataType: "json",
		async: false,
		success: function(data){
			if (!data.succeed) {
				$.alert(data.message);
				return result = false;
			}
			result = true;	
		},
		error:function(message){
			$.alert(message);
			result = false;
		}
	});

	if (result == false) {
		return false;
	}
	
	try {
		callback();
		return true;
	}
	catch(error) {
		return false;
	}
}


</script>

<body >

<div id="_roleList" class="span9">
</div>
 
</body>
</html>